package com.yugu.park.system.service.impl;

import cn.hutool.core.lang.UUID;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yugu.park.system.entity.SysLoginLogEntity;
import com.yugu.park.system.mapper.SysLoginLogMapper;
import com.yugu.park.system.service.SysLoginLogService;
import com.yugu.util.BeanCopyUtil;
import com.yugu.util.SearchPage;
import com.yugu.util.SysQueryParam;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;


@Service
@Transactional
public class SysLoginLogServiceImpl extends ServiceImpl<SysLoginLogMapper, SysLoginLogEntity> implements SysLoginLogService {
    @Resource
	private SysLoginLogMapper mapper;
	@Override
	public PageInfo<SysLoginLogEntity> page(SearchPage<SysQueryParam> search) {
		PageHelper.startPage(search.getPageNum(),search.getPageSize());
        List<SysLoginLogEntity> list = mapper.page(search.getSearch());
        return PageInfo.of(list);
	}
	@Override
	public void addOrUpdate(SysLoginLogEntity t) {
		SysLoginLogEntity old = mapper.selectById(t.getId());
		if(old!=null) {
			BeanCopyUtil.copyProperties(t,old);
			mapper.updateById(old);
		}else{
			t.setId(UUID.randomUUID().toString().replaceAll("-", ""));
			mapper.insert(t);
		}
	}
	@Override
	public void insertLoginLog(SysLoginLogEntity logininfor) {
		logininfor.setId(IdUtil.simpleUUID());
		mapper.insert(logininfor);
	}

}
